package com.blog.controller;
import com.blog.entity.message;
import com.blog.dao.DAO;
import com.blog.dao.MessageDao;
import java.util.ArrayList;
import java.util.List;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONArray;

@WebServlet("/getCommodityListServlet")
public class GetCommodityListServlet  extends HttpServlet{

	public static final long serialVersionUID=1L;

	@Override
	protected void doGet(HttpServletRequest req,HttpServletResponse resp) throws ServletException,IOException{
		this.doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req,HttpServletResponse resp) throws ServletException,IOException{
		PrintWriter out  = resp.getWriter();
		List<message> messages = new ArrayList<>();
		MessageDao messageDao = (MessageDao)MessageDao.getAbilityDAO(DAO.MessageDao);
		try {
			messages = messageDao.getList();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		JSONArray json = JSONArray.fromObject(messages);
		out.println(json.toString());
		out.flush();
		out.close();
	}


}
